/**
 * Copyright (C) 2007 The AsyncMail Group <asyncmail@googlegroups.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.asyncmail.queue;

import com.googlecode.asyncmail.common.MailEnvelope;

public class MailQueueItem {

    private int retries = 0;

    private long nextRetryTime = 0;

    private MailEnvelope mailEnv;

    private String errorMessage = null;

    public final static String MAIL_QUEUE_ITEM = "MAIL_QUEUE_ITEM";

    public MailQueueItem(MailEnvelope mailEnv) {
        if (mailEnv == null)
            throw new IllegalArgumentException("MailEnvelope cannot be null!");

        this.mailEnv = mailEnv;
    }

    /**
     * Return the retries which allready were done
     * 
     * @return retries
     */
    public int getRetries() {
        return retries;
    }

    public void increaseRetries() {
        retries++;
    }

    /**
     * Return true if the MailQueueItem should be tried to send again
     * 
     * @return
     */
    public long getNextRetry() {
        return nextRetryTime;
    }

    /**
     * Set the time in ms after which the MailQueueItem becomes readToProcess
     * again
     * 
     * @param retryTime
     */
    public void setNextRetry(long nextRetryTime) {
        this.nextRetryTime = nextRetryTime;
    }

    /**
     * Return the MailEnvelope which was used to build this MailQueueItem
     * 
     * @returnm mailEnv
     */
    public MailEnvelope getMailEnvelope() {
        return mailEnv;
    }

    /**
     * Set the error message on a failure while delivering
     * 
     * @param errorMessage
     */
    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    /**
     * Return the error message
     * 
     * @return
     */
    public String getErrorMessage() {
        return errorMessage;
    }

}
